import { pick } from 'ch4o';
import { createRouter, createWebHistory } from 'vue-router';
import routes from './router.idx'

console.log(111, routes);

// console.log(routes)
const router = createRouter({
    history: createWebHistory(),
    routes
});
/**
 * 获取当前可用的路由
 * @returns [Object Array] 当前可用的路由
 */
function getRoutes() {
    return routes;
}

function getStaticRoutes() {

    return routes.reduce((staticRoutes, route) => {
        const mkey = route?.meta?.moduleKey;
        if (mkey) {
            staticRoutes[mkey] = pick(['name', 'path', 'title'], route);
        }
        return staticRoutes;
    }, {});
}

const staticRoutes = getStaticRoutes();

export {
    router as default,
    getRoutes,
    staticRoutes,
};
